<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2018/7/16 0016
  Time: 上午 10:54
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://"
            + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
%>
<html>
<head>
    <head>
        <title>支付</title>
        <script src="../../js/jquery-3.3.1.min.js" charset="utf-8"></script>
        <script src="../../js/cookie/jquery.cookie.js" charset="utf-8"></script>
        <script src="../../layui-v2.2.5/layui/layui.js" charset="utf-8"></script>
        <link rel="stylesheet" href="../../layui-v2.2.5/layui/css/layui.css" media="all">
    </head>
</head>
<body>
<br><br><br>


<div class="layui-form">
    <form class="layui-form" action="">

        <c:choose>
            <c:when test="${record.alipayId!=null&&record.alipayId!=''}">

                <div class="layui-form-item">
                    <label class="layui-form-label">支付宝ID</label>
                    <div class="layui-input-block">
                        <input type="text" disabled id="alipayId" value="${record.alipayId}" class="layui-input"/>
                    </div>
                </div>

            </c:when>
            <c:when test="${record.alipayId==null||record.alipayId==''}">

                <div class="layui-form-item">
                    <label class="layui-form-label">真实姓名</label>
                    <div class="layui-input-block">
                        <input type="text" id="realName" value="${record.realName}" class="layui-input"/>
                    </div>
                </div>


                <div class="layui-form-item">
                    <label class="layui-form-label">支付宝账户</label>
                    <div class="layui-input-block">
                        <input type="text" id="alipayAccount" value="${record.alipayAccount}" class="layui-input"/>
                    </div>
                </div>

            </c:when>
        </c:choose>

        <div class="layui-form-item">
            <label class="layui-form-label">支付金额</label>
            <div class="layui-input-block">
                <input type="number" id="money" value="${record.money}" class="layui-input"/>
            </div>
        </div>

        <div class="layui-form-item">

            <div class="layui-input-block">
                <button type="button" class="layui-btn" onclick="update('${record.cardId}');">支付</button>
            </div>
        </div>


    </form>


</div>


<script>
    layui.use('layer', function () {
        var layer = layui.layer;

    });

    function update(id) {
        $.ajax({
            url: '/shop/toPayForMember',
            type: 'POST', //GET
            async: true, //或false,是否异步
            data: {
                'cardId': id,
                'money': $('#money').val(),
                'realName': $('#realName').val(),
                'alipayAccount': $('#alipayAccount').val()
            },
            timeout: 5000, //超时时间
            dataType: 'json', //返回的数据格式：json/xml/html/script/jsonp/text
            beforeSend: function (xhr) {
                /*console.log(xhr)
                console.log('发送前')*/
            },
            success: function (data) {
                if (data.result) {
                    layer.msg("支付成功");
                } else {
                    layer.msg(data.msg);
                }
            },
            error: function (xhr, textStatus) {
                console.log('错误')
                console.log(xhr)
                console.log(textStatus)
            },
            complete: function () {
                //console.log('结束')
            }
        });
    }


</script>
</body>
</html>
